/**
 *
 */
package org.suren.littlebird.actions.bundle;

import java.util.List;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TableViewer;
import org.suren.littlebird.Activator;
import org.suren.littlebird.actions.Reload;
import org.suren.littlebird.views.InstallBundleDialog;

/**
 * @author suren
 *
 */
public class SuRenBundleInstallAction extends Action
{
	private InstallBundleDialog dialog;
	private SuRenBundleController controller;
	private Reload bundleReload;

	private List<String>	pathList;

	/**
	 * @param viewer
	 * @param dialog
	 */
	public SuRenBundleInstallAction(TableViewer viewer, InstallBundleDialog dialog, Reload bundleReload)
	{
		this.dialog = dialog;
		this.bundleReload = bundleReload;
		this.controller = new DefaultSuRenBundleController();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.action.Action#getText()
	 */
	@Override
	public String getText()
	{
		return "Install";
	}

	@Override
	public ImageDescriptor getImageDescriptor()
	{
		return Activator.getImageDescriptor("icons/install.gif");
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.action.Action#run()
	 */
	@Override
	public void run()
	{
		try
		{
			System.out.println(getPathList());
			if(getPathList() == null || getPathList().size() == 0)
			{
				return;
			}

			if(controller.control(SuRenBundleController.INSTALL, getPathList(), 0) > 0)
			{
				bundleReload.reload(null, null);
			}
		}
		finally
		{
			setPathList(null);
		}
	}

	/**
	 * @return the pathList
	 */
	public List<String> getPathList()
	{
		return pathList;
	}

	/**
	 * @param pathList the pathList to set
	 */
	public void setPathList(List<String> pathList)
	{
		this.pathList = pathList;
	}
}
